const app = getApp()
import {
  HomeIndex
} from 'index-modal.js';
import {
  Config
} from '../../../utils/config.js';
var Function = require("../../../utils/function.js");
var index = new HomeIndex(); //实例化 首页 对象
Page({
  data: {
    url:Config.Url,
    windowWidth:0,
    hideJin:false,
    id:'',
    yanmi:{},
    yanmi_du:{},
    price:0,
    comid:'', //服务id查询价格
    showLingth:4,
  },
  showAll:function(){
    let that=this;
    that.setData({
      showLingth: that.yanmi_du.order.length
    })
  },
  onLoad: function(options) {
    this.setData({
      id:options.id,
      comp_id: options.comp_id,
      goods_id: options.goods_id
    })
    this._getqmos()
    this._linespeed()
    this._priceMode(options.comp_id);
  },

  showModal(){
    this.setData({hideJin:true})
  },
  hideModal(){
    this.setData({ hideJin:false})
  },

  linkTo(){    //确认取号
    let members = wx.getStorageSync('members') || [];
    if(Array.isArray(members)){
      wx.showModal({
        title:'登录',
        content: '请授权登录',
        success:function(res){
          if(res.confirm){
            wx.navigateTo({
              url: '/pages/auth/auth',
            })
          }
        },fail(err){}
      })
    }else{
      this._getArsuer()  
    }
  
  },
  formSubmit(e) {
    this.setData({
      formId: e.detail.formId
    })
  },
  _getArsuer(){  //确认取号
    let that = this;
    let uid  = wx.getStorageSync('members').id;
    let data = {
      doctor_id: that.data.id,
      uid,
      comp_id: that.data.comp_id,
      num: that.data.yanmi.number,
      time: that.data.yanmi.time,
      goods_id: that.data.goods_id,
      form_id: that.data.formId
    }
    index.getArsuer(data,(res)=>{
      if(res.code == 200){
        wx.showToast({
          title: res.msg,
          title: "取号成功",
          duration:1500,
          icon:'success'
        })
        setTimeout(()=>{
          wx.navigateTo({
            url: '../success/success?id=' + that.data.id + "&plove=" + JSON.stringify(res.data)
          })
        },1000)
      }else{
        wx.showToast({
          title: res.msg,
          duration:1000,
          icon:'none'
        })
        setTimeout(()=>{
          wx.navigateBack({
            delta: 3
          })
        },2000)
      
      }
    })
  },
  _getqmos(){
    let that =this;
    let data ={
      id:that.data.id,
      uid: wx.getStorageSync('members').id
    }
    index.getqmos(data,(res)=>{
       if(res.code == 200){
          that.setData({
            yanmi:res.data,
            
          })
       }
    })
  },

  _linespeed(){
    let that = this;
    let data = {
      id: that.data.id,
      uid: wx.getStorageSync('members').id,

    }
    index.linespeed(data, (res) => {
      if (res.code == 200) {
        that.setData({
          yanmi_du:res.data,
          xingxing: Math.round(res.data.score)
        })
      }
    })
  },

  _priceMode(id){  //获取服务价格
    let that =this;
    let data ={
      id: id
    };
    index.priceMode(data,(res)=>{
      if(res.code == 200){
        that.setData({price:res.data})
      }
    })
  },

  seletcimid(e){
      let comid = e.currentTarget.dataset.index.split('=');
      if (comid[0] == this.data.activelav ){return;}
      this.setData({
        comid: comid[1],
        activelav:comid[0]
      })
       this._priceMode()
  }
  
})